#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
	int n, i, count = 0;
	int arr[1001];
	scanf("%d", &n);
	for (i = 0; i < n; i++)
	{
		scanf("%d", &arr[i]);
		if (arr[i])
		{
			printf("%d ", arr[i]);
			count++;
		}
	}
	for (i = 0; i < n - count; i++)
	{
		printf("0 ");
	}
	return 0;
}